<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="注水泥塞管柱深度(m)" prop="depth">
				<u-input :border="border" placeholder="请输入注水泥塞管柱深度" v-model="model.depth" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="替入灰浆量(m³)" prop="slurryVolume">
				<u-input :border="border" placeholder="请输入替入灰浆量" v-model="model.slurryVolume" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="油管内径(m)" prop="tubingInnerDiameter">
				<u-input :border="border" placeholder="请输入油管内径" v-model="model.tubingInnerDiameter" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="套管内径(m)" prop="casingInnerDiameter">
				<u-input :border="border" placeholder="请输入套管内径" v-model="model.casingInnerDiameter" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="油管外径(m)" prop="tubingOuterDiameter">
				<u-input :border="border" placeholder="请输入油管外径" v-model="model.tubingOuterDiameter" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;"  :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="清水顶替量" prop="displacementVolume">
					<span v-if="model.displacementVolume"> {{model.displacementVolume}} m³ </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">V = π × (d/2)² × h + 附加量</view>
				<view class="u-item-desc">h = H - V1 ÷ {π × [(D/2)² - (d1/2)² + (d/2)²]}</view>
				<view class="u-item-desc">式中：H — 注水泥塞管柱深度，单位 m</view>
				<view class="u-item-desc">h — 顶替深度，单位 m</view>
				<view class="u-item-desc">d — 油管内径，单位 m</view>
				<view class="u-item-desc">V1 — 替入灰浆量，单位 m³</view>
				<view class="u-item-desc">D — 套管内径，单位 m</view>
				<view class="u-item-desc">d1 — 油管外径，单位 m</view>
				<view class="u-item-desc">V — 顶替量，单位 m³</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					depth: '',
					slurryVolume: '',
					tubingInnerDiameter: '',
					casingInnerDiameter: '',
					tubingOuterDiameter: '',
					displacementVolume: ''
				},
				rules: {
					depth: [{
						required: true,
						message: '请输入注水泥塞管柱深度',
						trigger: 'blur'
					}],
					slurryVolume: [{
						required: true,
						message: '请输入替入灰浆量',
						trigger: 'blur'
					}],
					tubingInnerDiameter: [{
						required: true,
						message: '请输入油管内径',
						trigger: 'blur'
					}],
					casingInnerDiameter: [{
						required: true,
						message: '请输入套管内径',
						trigger: 'blur'
					}],
					tubingOuterDiameter: [{
						required: true,
						message: '请输入油管外径',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						const H = parseFloat(this.model.depth);
						const V1 = parseFloat(this.model.slurryVolume);
						const d = parseFloat(this.model.tubingInnerDiameter);
						const D = parseFloat(this.model.casingInnerDiameter);
						const d1 = parseFloat(this.model.tubingOuterDiameter);
						
						// 计算顶替深度 h
						const denominator = Math.PI * (Math.pow(D/2, 2) - Math.pow(d1/2, 2) + Math.pow(d/2, 2));
						const h = H - V1 / denominator;
						
						// 计算顶替量 V
						const baseVolume = Math.PI * Math.pow(d/2, 2) * h;
						// 添加10%的附加量
						const additionalVolume = baseVolume * 0.1;
						this.model.displacementVolume = (baseVolume + additionalVolume).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>